package com.hinata.hinataimageloader;

import android.app.Application;
import android.content.Context;

import com.nostra13.universalimageloader.cache.disc.naming.Md5FileNameGenerator;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
import com.nostra13.universalimageloader.core.assist.QueueProcessingType;


/**
 * Created by Hinata on 2017/3/30.
 */

public class ImageLoaderApplication extends Application{
    @Override
    public void onCreate() {
        super.onCreate();
        initImageLoader(getApplicationContext());

    }

    public static void initImageLoader(Context context){

        //File cacheDir= StorageUtils.getOwnCacheDirectory(context,"imageloader/Cache");


        ImageLoaderConfiguration.Builder imgLoaderConfig=new ImageLoaderConfiguration.Builder(context);
        imgLoaderConfig.threadPriority(Thread.NORM_PRIORITY - 2);
        imgLoaderConfig.denyCacheImageMultipleSizesInMemory();
        imgLoaderConfig.diskCacheFileNameGenerator(new Md5FileNameGenerator());
        imgLoaderConfig.diskCacheSize(50 * 1024 * 1024); // 50 MiB
        imgLoaderConfig.tasksProcessingOrder(QueueProcessingType.LIFO);
        imgLoaderConfig.writeDebugLogs(); // Remove for release app

        ImageLoader.getInstance().init(imgLoaderConfig.build());


    }
}
